<template>
  <div class="cate-tab-bar">
    <ul class="tab-bar">
      <li
        v-for="(item, index) in categories"
        :key="index"
        @click="selectItem(index)"
        :class="{ active: currentIndex === index }"
      >
        {{ item.title }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      currentIndex: 0,
    };
  },
  props: {
    categories: {
      type: Array,
      defult() {
        return [];
      },
    },
  },
  methods: {
    selectItem(index) {
      console.log(index);
      this.currentIndex = index;
      this.$emit("selectItem", index);
    },
  },
};
</script>

<style scoped>
.tab-bar li {
  font-size: 14px;
  padding-left: 20px;
  width: 100px;
  height: 50px;
  line-height: 50px;
}
.active {
  color: #ff8198;
  border-left: 5px solid #ff8198;
}
</style>